package org.homly.admin.tag.product;

import java.util.HashMap;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.homly.service.ProductService;
import org.homly.tool.StringTool;

/*
 * 查询一个配置
 */
@SuppressWarnings("serial")
public class ConfigTag extends TagSupport {

	private String name;
	private String id;

	@SuppressWarnings("unchecked")
	@Override
	public int doStartTag() throws JspException {

		HashMap<String, String> config = null;

		Integer idNum = null;
		if (id == null || !StringTool.isNumber(id)) {
			pageContext.setAttribute(name, new HashMap<String, String>());

			return SKIP_BODY;
		}
		idNum = Integer.valueOf(id);

		HashMap para = new HashMap();
		para.put("id", idNum);

		ProductService productService = new ProductService();
		try {
			config = productService.getConfig(para);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		pageContext.setAttribute(name, config);

		return SKIP_BODY;
	}

	public void setName(String name) {
		this.name = name;
	}
	public void setId(String id) {
		this.id = id;
	}
}
